using System.Web.Mvc;
using ExtendedMvc.Html;

namespace ExtendedMvc.Elements {
	public class Link : LinkBase<Link> {
		public Link(string content, string link, string id = null) : base(content, link, id) { }
	}

	public abstract class LinkBase<T> : VisibleElement<T> where T : LinkBase<T> {
		private string _content;
		private string _link;

		protected LinkBase(string content, string link, string id = null)
			: base(HtmlTag.Link, id) {
			Content(content);
			Link(link);
		}

		protected virtual T Content(string value) {
			_content = value;
			return (T)this;
		}

		protected virtual T Link(string value) {
			_link = value;
			return (T)this;
		}

		protected override TagRenderMode TagRenderMode { get { return TagRenderMode.Normal; } }

		protected override void Prepare() {
			if (_link != null) SetAttribute(HtmlAttribute.HRef, _link);
			base.Prepare();
		}

		protected override void SetContent() {
			if (_content == null) return;
			Builder.InnerHtml = _content;
		}
	}
}